package com.lemon.smartsafetynew.ui.activity.device;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafetynew.entity.common.DateTypeEnum;
import com.lemon.smartsafetynew.entity.device.DeviceVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.lemon.smartsafetynew.util.device.DeviceUtils;
import com.rengwuxian.materialedittext.MaterialEditText;

import butterknife.Bind;

/**
 * Created by Andrew on 2017/9/26.
 */

public class DeviceDetailActivity extends SwipeBackActivity {

    @Bind(R.id.device_type_tv)
    TextView deviceTypeTv;
    @Bind(R.id.device_type_arrow_imageView)
    ImageView deviceTypeArrowImageView;
    @Bind(R.id.device_name_tv)
    TextView deviceNameTv;
    @Bind(R.id.device_name_et)
    EditText deviceNameEt;
    @Bind(R.id.device_num_tv)
    TextView deviceNumTv;
    @Bind(R.id.device_num_et)
    EditText deviceNumEt;
    @Bind(R.id.device_brand_tv)
    TextView deviceBrandTv;
    @Bind(R.id.device_brand_et)
    EditText deviceBrandEt;
    @Bind(R.id.device_version_tv)
    TextView deviceVersionTv;
    @Bind(R.id.device_version_et)
    EditText deviceVersionEt;
    @Bind(R.id.device_manufacturer_tv)
    TextView deviceManufacturerTv;
    @Bind(R.id.device_manufacturer_et)
    EditText deviceManufacturerEt;
    @Bind(R.id.device_supplier_tv)
    TextView deviceSupplierTv;
    @Bind(R.id.device_supplier_et)
    EditText deviceSupplierEt;
    @Bind(R.id.device_buy_time_tv)
    TextView deviceBuyTimeTv;
    @Bind(R.id.device_buy_time_arrow_imageView)
    ImageView deviceBuyTimeArrowImageView;
    @Bind(R.id.device_position_tv)
    TextView devicePositionTv;
    @Bind(R.id.device_position_arrow_imageView)
    ImageView devicePositionArrowImageView;
    @Bind(R.id.device_status_tv)
    TextView deviceStatusTv;
    @Bind(R.id.device_status_arrow_imageView)
    ImageView deviceStatusArrowImageView;
    @Bind(R.id.device_department_tv)
    TextView deviceDepartmentTv;
    @Bind(R.id.device_department_arrow_imageView)
    ImageView deviceDepartmentArrowImageView;
    @Bind(R.id.device_charge_tv)
    TextView deviceChargeTv;
    @Bind(R.id.device_charge_arrow_imageView)
    ImageView deviceChargeArrowImageView;
    @Bind(R.id.device_mark_tv)
    TextView deviceMarkTv;
    @Bind(R.id.device_remark_et)
    MaterialEditText deviceRemarkEt;
    @Bind(R.id.device_remark_layout)
    LinearLayout deviceRemarkLayout;

    private static DeviceVo mDeviceVo;

    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();

        Bundle bundle = getIntent().getExtras();

        if (bundle != null) {
            if (bundle.containsKey(KeyConstants.KEY_DEVICE_VO)) {
                mDeviceVo = (DeviceVo)bundle.getSerializable(KeyConstants.KEY_DEVICE_VO);
            }
        }
    }

    @Override
    protected void initTitle() {
        this.setBarTitle("设备详情");
    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(DeviceDetailActivity.this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_device_detail;
    }

    @Override
    protected void initViews() {
        super.initViews();

        initCommon();
    }

    /**
     * 初始化页面数据
     */
    private void initCommon() {

        deviceTypeTv.setText(CommonUtil.avoidNullString(mDeviceVo.getGroup()));
        deviceNameTv.setText(CommonUtil.avoidNullString(mDeviceVo.getName()));
        deviceNumTv.setText(CommonUtil.avoidNullString(mDeviceVo.getCode()));
        deviceBrandTv.setText(CommonUtil.avoidNullString(mDeviceVo.getBrand()));
        deviceVersionTv.setText(CommonUtil.avoidNullString(mDeviceVo.getVersion()));
        deviceManufacturerTv.setText(CommonUtil.avoidNullString(mDeviceVo.getManufactor()));
        deviceSupplierTv.setText(CommonUtil.avoidNullString(mDeviceVo.getSupplier()));
        deviceBuyTimeTv.setText(CommonUtil.secondToTimeStr(mDeviceVo.getBuy_time(), DateTypeEnum.DAY));
        devicePositionTv.setText(CommonUtil.avoidNullString(mDeviceVo.getBuilding_name())
                + " " + CommonUtil.avoidNullString(mDeviceVo.getFloor_number()) + "楼"
                + " "  + CommonUtil.avoidNullString(mDeviceVo.getPosition_mark()));

        deviceStatusTv.setText(DeviceUtils.deviceStatus[DeviceUtils.getStatus(mDeviceVo.getStatus())]);
        deviceDepartmentTv.setText(CommonUtil.avoidNullString(mDeviceVo.getDepartment_name()));
        deviceChargeTv.setText(CommonUtil.avoidNullString(mDeviceVo.getCharge_id()));

        deviceMarkTv.setText(CommonUtil.avoidNullString(mDeviceVo.getRemark()));

    }
}
